package com.juku2024.juku.tools

import android.widget.ImageView
import coil.load
import com.juku2024.juku.R

object ImageUtils {

    fun loadImage(imageView: ImageView?, url: Any?){
        if (imageView == null || url == null) {
            return
        }
        imageView.load(url) {
            crossfade(300)
            error(R.drawable.ic_error_default)
        }
    }

    fun loadImageBanner(imageView: ImageView?, url: Any?){
        if (imageView == null || url == null) {
            return
        }
        val r = AppUtils.findActivity(imageView.context)?.resources?.getDimensionPixelSize(R.dimen.d_12)?:0
        imageView.load(url) {
            error(R.drawable.bg_banner_error)
            transformations(coil.transform.RoundedCornersTransformation(r.toFloat()))
        }
    }


    fun loadImageH(imageView: ImageView?, url: Any?){
        if (imageView == null || url == null) {
            return
        }
        val r = AppUtils.findActivity(imageView.context)?.resources?.getDimensionPixelSize(R.dimen.d_6)?:0
        imageView.load(url) {
            error(R.drawable.bg_banner_error)
            transformations(coil.transform.RoundedCornersTransformation(r.toFloat()))
        }
    }


    fun loadImageV(imageView: ImageView?, url: Any?){
        if (imageView == null || url == null) {
            return
        }
        val r = AppUtils.findActivity(imageView.context)?.resources?.getDimensionPixelSize(R.dimen.d_6)?:0
        imageView.load(url) {
            error(R.drawable.ic_error_default)
            transformations(coil.transform.RoundedCornersTransformation(r.toFloat()))
        }
    }

    fun loadImageGif(imageView: ImageView?, url: Any?){
        if (imageView == null || url == null) {
            return
        }
        imageView.load(url) {
            error(R.drawable.ic_error_default)
        }
    }




}